package com.example.moshudriver.activity;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.BeeFramework.model.BusinessResponse;
import com.sgr.dykdriver.R;
import com.example.moshudriver.model.UserBalanceModel;
import com.example.moshudriver.protocol.ApiInterface;
import com.external.androidquery.callback.AjaxStatus;

public class Withdraw_PasswordActivity extends Activity implements BusinessResponse {
        EditText confirm_withdraw_pwd,withdraw_pwd;
        Button withward_comfirm_pwd;
        UserBalanceModel withdrawModel;
        TextView top_view_title;
        ImageView top_view_back;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_withward_password);
		withdrawModel=new UserBalanceModel(this);
		withdrawModel.addResponseListener(this);
		invitView();
	}

	private void invitView() {
		top_view_back=(ImageView)findViewById(R.id.top_view_back);
		top_view_title=(TextView)findViewById(R.id.top_view_title);
		top_view_title.setText("设置新的支付密码");
		confirm_withdraw_pwd=(EditText)findViewById(R.id.confirm_withdraw_pwd);
	    withdraw_pwd=(EditText)findViewById(R.id.withdraw_pwd);
	    withward_comfirm_pwd=(Button)findViewById(R.id.withward_comfirm_pwd);
	    withward_comfirm_pwd.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				if(confirm_withdraw_pwd.length()<6){
					Toast.makeText(Withdraw_PasswordActivity.this, "密码必须大于六位数", 2000).show();
				}else if(!confirm_withdraw_pwd.getText().toString().equals(withdraw_pwd.getText().toString())){
					Toast.makeText(Withdraw_PasswordActivity.this, "两次输入的密码不一样", 2000).show();
				}else{
					withdrawModel.SetNewPwd(confirm_withdraw_pwd.getText().toString());
				}
				
			}
		});
	    top_view_back.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				Withdraw_PasswordActivity.this.finish();
				
			}
		});
		
	}

	@Override
	public void OnMessageResponse(String url, JSONObject jo, AjaxStatus status)
			throws JSONException {
		if(url.endsWith(ApiInterface.WITHDRAW_SET_PWD)){
			Intent intent = new Intent(Withdraw_PasswordActivity.this,WithdrawActivity.class);
			startActivity(intent);
			Toast.makeText(this, "设置支付密码成功", 2000).show();
			finish();
			
		}
		
	}



}
